<?php
$dbh = new PDO('mysql:host=localhost;dbname=blog', 'root', '');
// Check if a blog title already exists
function blogExists($dbh, $blogTitle) {
    $sql = "SELECT COUNT(*) AS cnt FROM blogList WHERE blogTitle=".$dbh->quote($blogTitle);		
		$row = $dbh->prepare($sql);
    $stmt->execute();							 
    //$row = $dbh->prepare($sql);
		$row = $dbh->execute();
    return !empty($row['cnt' ]);
}
function getBlog($dbh) {
    $sql = "SELECT blogText FROM blogList WHERE blogTitle = '$_POST[blogTitle]'";
    $blog = $dbh->prepare($sql);
		echo htmlentities($sql, ENT_QUOTES);
		return $dbh->exec($sql);
}
$blog = getBlog($dbh);
$error = '' ;
$success = '' ;
$blog = isset($_POST['blogTitle' ]) ? $_POST['blogTitle' ] : '' ;
if ($_SERVER['REQUEST_METHOD' ] == 'POST' ) {
	  if (updateBlog($dbh, $blogTitle, $blogText)) {
        $success = "Thank you, blog has been added.";
		}
    elseif (!blogExists($dbh, $blogTitle)) {
        $error = "Blog Title does not exist.";
    }
}
?>














<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>
<body>

</body>
</html>
